//
//  SFSettingsViewController.m
//  SFNavigationBarManager_Example
//
//  Created by shen on 2021/11/17.
//  Copyright © 2021 yangshen. All rights reserved.
//

#import "SFSettingsViewController.h"
#import "SFNavigationBarData.h"

@interface SFSettingsViewController ()

@end

@implementation SFSettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = [SFNavigationBarData nameWithStyle:self.selectIndex];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.selectBarTintColor ? 6 : 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    cell.textLabel.text = [SFNavigationBarData nameWithStyle:indexPath.row];
    cell.accessoryType = (indexPath.row == self.selectIndex) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    !self.selectIndexBlok ?: self.selectIndexBlok(indexPath.row);
    [self.navigationController popViewControllerAnimated:YES];
}

@end
